package com.ljm.notice.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ljm.notice.api.LjmNoticeApi;
import com.ljm.notice.dto.LjmNoticeDto;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 新闻公告 前端控制器
 * </p>
 *
 * @author HuamingChen
 * @since 2020-10-29
 */
@Api("新闻公告")
@Controller
@RequestMapping("/app/notice")
public class LjmNoticeController {

    /**
    * 新闻公告接口
    */
    @Resource
    private LjmNoticeApi ljmNoticeApi;

    @ApiOperation(value="保存新闻公告")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult save(@ApiParam(value="新闻公告") @RequestBody @Validated LjmNoticeDto dto){
        ljmNoticeApi.saveData(dto);
        return ResultUtil.success();
    }

    @ApiOperation(value="删除新闻公告")
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult del(@ApiParam(value="主键") @RequestBody List<Long> ids){
        ljmNoticeApi.batchDel(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value="获取新闻公告")
    @RequestMapping(value = "/getById",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getById(@ApiParam(value="主键") @RequestParam Long id){
        return ResultUtil.successData(ljmNoticeApi.getDataById(id));
    }

    @ApiOperation(value="分页获取新闻公告")
    @RequestMapping(value = "/getByPage",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getByPage(
            @ApiParam(value="标题") @RequestParam(required = false) String title,
            @ApiParam(value="来源") @RequestParam(required = false) String fdOrigin,
            @ApiParam(value="类型") @RequestParam(required = false) Integer fdType,
            @ApiParam(value="页码") @RequestParam(defaultValue = "1") Integer pageNo,
            @ApiParam(value="页大小") @RequestParam(defaultValue = "10") Integer pageSize){
        return ResultUtil.successData(ljmNoticeApi.getDataByPage(new LjmNoticeDto(title,fdOrigin,fdType,pageNo,pageSize)));
    }
}
